const koaRouter = require('@koa/router')
const { registerUser, login, modifyPassword } = require('../controller/user.controller')
const { userValidtor, verifyUser, verifyUserLogin } = require('../middleware/user.middleware')
const bcryptPassword = require('../utils/bcryptPassword')
const { auth } = require('../middleware/auth.middleware')

// 创建用户路由,定义路由映射
const userRouter = new koaRouter({ 'prefix': '/users' })
// 用户注册
userRouter.post('/register', userValidtor, verifyUser, bcryptPassword, registerUser)
// 用户登录
userRouter.post('/login', userValidtor, verifyUserLogin, login)
// 修改密码
userRouter.patch('/', auth, bcryptPassword, modifyPassword)
module.exports = userRouter